package com.supermarket_project.controller;

import com.supermarket_project.common.R;
import com.supermarket_project.pojo.Goods;
import com.supermarket_project.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/supermarket/goods")
@CrossOrigin
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/addGoods")
    public R addGoods(@RequestBody Goods goods){
        return goodsService.addGoods(goods);
    }

    @GetMapping("/pageGoods")
    public R pageGoods(int pageNum,
                       int pageSize,
                       Integer gCategoryId,
                       String goodsName,
                       String barcode){
        return goodsService.pageGoods(pageNum,pageSize,gCategoryId,goodsName,barcode);
    }

    @PostMapping("/updateGoods")
    public R updateGoods(@RequestBody Goods goods){
        return goodsService.updateGoods(goods);
    }

    @GetMapping("/queryGoods/{goodsId}")
    public R queryGoods(@PathVariable("goodsId") int goodsId){
        return goodsService.queryGoods(goodsId);
    }

    @DeleteMapping("/deleteGoods/{goodsId}")
    public R deleteGoods(@PathVariable("goodsId") int goodsId){
        return goodsService.deleteGoods(goodsId);
    }

    @PutMapping("/lockGoods/{goodsId}/{status}")
    public R lockGoods(@PathVariable("goodsId") int goodsId,
                       @PathVariable("status") int status){
        return goodsService.lockGoods(goodsId,status);
    }
}
